#import "Deamon.h"
#import <stdbool.h>

@implementation Deamon
/** setters/getters **/
- (id) lvl: (int) lvl_value {lvl = lvl_value; return self;}
- (int) lvl{ return lvl; }

- (id) hitpoints: (int) hitpoints_value {hitpoints = hitpoints_value;return self;}
- (int) hitpoints { return hitpoints; }

- (id) name: (char*) name_value{name = name_value; return self; }
- (char*) name { return name;}

/**
 * assigns weapon to deamon
 */
-(void) useWeapon: (Weapon*)weaponToUse {
	weapon = weaponToUse;
}


- (id) receiveHit: (int) hp {
	if(hitpoints == 0) {
		// printf("\ncan't hurt dead %s", [self toString]);
		return self;
	}
	hitpoints -= hp;
	if(hitpoints <= 0) {
		// printf("\n%s says: \"Bye bye cruel hell!\"", [self toString]);
		hitpoints = 0;
	}
	return self;
}

- (int) hit{
	return [weapon attackPower];
}

- (bool) isDead{return hitpoints <= 0;}

- (char*) toString {
	char* result[1024]; // todo: name max size + level max size + hitpoints max size + format size(32 for now)
	sprintf(result, "{Deamon name=%s, lvl=%d, hitpoints=%d}",name, lvl, hitpoints);
	return result;
}
@end
